<template>
  <view class="server_box">
    <view>
      <view
          @click="openService"
          style="width: 70rpx;height: 70rpx;background-color: #fdfdfd;display: flex;flex-direction: column;align-items: center;justify-content: center;box-shadow: 0 3rpx 6rpx rgba(0, 0, 0, 0.3);border-radius: 100rpx;">
        <image :src="BaseImgUrl + '/home/pz/kefu.png'" mode="widthFix" style="height:33rpx;width:33rpx"></image>
        <view style="color: #323232;font-size: 18rpx;">客服</view>
      </view>
    </view>
    <view v-if="isHome">
      <view
          @click="toNewUser"
          style="margin-top:16rpx;width: 70rpx;height: 70rpx;background-color: #fdfdfd;display: flex;flex-direction: column;align-items: center;justify-content: center;box-shadow: 0 3rpx 6rpx rgba(0, 0, 0, 0.3);border-radius: 100rpx;">
        <image :src="BaseImgUrl + '/home/pz/new_user.png'" mode="widthFix" style="height:33rpx;width:33rpx"></image>
        <view style="color: #323232;font-size: 18rpx;">教程</view>
      </view>
    </view>
  </view>
</template>

<script setup>
import {useCommonInfoStore} from "../stores/modules/commonInfo";
import {BaseImgUrl} from "../utils/lshttp";

const props = defineProps({
  isHome: {
    type: Boolean,
    default: false
  },
})
const toNewUser = () => {
  uni.navigateTo({
    url: "/pages/index/mt_phone_help"
  })
}
const openService = () => {
  const commonInfoStore = useCommonInfoStore()
  console.log('commonInfoStore.serviceUrl', commonInfoStore.serviceUrl)
  // #ifdef MP
  wx.openCustomerServiceChat({
    //企业微信的企业id
    corpId: commonInfoStore.serviceUrl.applet.appid,
    extInfo: {
      //客服链接
      url: commonInfoStore.serviceUrl.applet.path
    },
  })
  // #endif
  // #ifdef APP-PLUS
  plus.share.getServices(res => {
    const wxServices = res.find(i => i.id.toString() === 'weixin')
    if (wxServices) {
      wxServices.openCustomerServiceChat({
        corpid: commonInfoStore.serviceUrl.app.corpId,
        url: commonInfoStore.serviceUrl.app.url
      })
    }
  }, function (res) {
    console.log(JSON.stringify(res));
  })
  // #endif
  // #ifdef H5
  window.location.href = commonInfoStore.serviceUrl.h5.url
  // #endif
}
</script>

<style lang="scss" scoped>

.server_box {
  position: fixed;
  right: 10rpx;
  top: 20%;
  z-index: 100;
  border-radius: 50%;

  .icon {
    width: 38rpx;
    height: 38rpx;
  }

  .text {
    font-size: 20rpx;
    color: #333;
  }
}
</style>
